package com.sendpo.zjx.sendpo.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.View;
import android.webkit.WebView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sendpo.zjx.sendpo.R;
import com.sendpo.zjx.sendpo.table.Officalmessage;
import com.sendpo.zjx.sendpo.utils.Tools;

import java.net.URL;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by zjx on 2018
 */

public class OfficalMessageInfoActivity extends AppCompatActivity {
    Officalmessage data;
    Html.ImageGetter imageGetter = new Html.ImageGetter() {
        public Drawable getDrawable(String result) {

            try {
                Drawable is = Drawable.createFromStream(new URL(result).openStream(), "");
                is.setBounds(0, 0, is.getIntrinsicWidth(), is.getIntrinsicHeight());
                return is;
            } catch (Exception paramAnonymousString) {
                paramAnonymousString.printStackTrace();
            }
            return null;
        }
    };
    @BindView(R.id.backbt)
    RelativeLayout backbt;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.message_title)
    TextView messageTitle;
    @BindView(R.id.message_date)
    TextView messageDate;
    @BindView(R.id.web_view)
    WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity__officalmessage);
        ButterKnife.bind(this);
        Tools.initStatus(this, R.color.black);
        initComponent();

    }

    private void initComponent() {
        data = ((Officalmessage)getIntent().getSerializableExtra("data"));
        messageTitle.setText(this.data.getMessageTitle());
        webView.loadDataWithBaseURL(null, this.data.getMessageContent(), "text/html", "utf-8", null);
        messageDate.setText(Tools.getDateBeforeAfter(Tools.getStringtoDate(this.data.getMessageCreatedate(), "yyyy-MM-dd HH:mm:ss").longValue()));
    }

    @OnClick(value = {R.id.backbt})
    public void onMyClick(View view) {
        switch (view.getId()) {
            case R.id.backbt:
                finish();
                break;
        }
    }
}
